/**
 * 安徽远望科技有限公司
 */
package com.smartwebx.ha.web.gis.module.screen;

import static com.smartwebx.ha.web.admin.common.HaConstant.HA_USER_SESSION_KEY;

import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.text.ParseException;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.citrus.turbine.dataresolver.Param;
import com.google.gson.Gson;
import com.smartwebx.ha.biz.assign.HaAreaManager;
import com.smartwebx.ha.dal.assign.bean.HaArea;
import com.smartwebx.ha.util.KmlProperty;
import com.smartwebx.ha.util.VisoLine;
import com.smartwebx.ha.web.admin.common.HaUserSys;
import com.smartwebx.ha.web.util.kml.ReadKml;

/**
 * 类描述：
 * 
 * @author: 程子清
 * @date： 日期：2011-1-11 时间：上午09:45:08
 * @version 1.0
 */
public class VisoLineScreen extends BasicScreen {
	@Autowired
	private HttpSession session;
	@Autowired
	private HaAreaManager haAreaManager;

	/**
	 * 
	 */
	private static final long serialVersionUID = -295098160699213675L;
	private String id = "visoline";
	private String title = "title";

	public void setTitle(String title) {
		this.title = title;
	}

	private String arrayData = "[[\"119.0594\",\"32.087\",\"1.0\",\"安基山水库1.0\"],[\"119.0791\",\"32.0723\",\"1.0\",\"窑湾水库1.0\"],[\"119.59\",\"34\",\"0.6\",\"王圩0.6\"],[\"118.08111\",\"33.31033\",\"0.5\",\"王铺水库0.5\"],[\"119.372634\",\"31.397552\",\"0.5\",\"大溪水库0.5\"],[\"118.7854\",\"32.5271\",\"0.5\",\"何营水库0.5\"],[\"118.7445\",\"32.4389\",\"0.5\",\"傅湾水库0.5\"],[\"118.7322\",\"32.5553\",\"0.5\",\"侯营水库0.5\"],[\"118.5816\",\"32.5707\",\"0.5\",\"彭家港水库0.5\"],[\"119.009737\",\"31.739377\",\"0.5\",\"夏家边0.5\"],[\"118.922593\",\"31.773045\",\"0.5\",\"艾园0.5\"],[\"119.057778\",\"32.087778\",\"0.5\",\"安基山0.5\"],[\"119.0258\",\"32.006\",\"0.5\",\"潭山水库0.5\"],[\"118.7303\",\"31.7187\",\"0.5\",\"鸡笼水库0.5\"],[\"118.8646\",\"31.6664\",\"0.5\",\"回龙坳水库0.5\"],[\"118.7138\",\"31.8845\",\"0.5\",\"赵宕水库0.5\"],[\"118.7273\",\"31.881\",\"0.5\",\"竹塘水库0.5\"],[\"118.7042\",\"31.8241\",\"0.5\",\"冬瓜塘水库0.5\"],[\"118.9216\",\"31.9321\",\"0.5\",\"东焦水库0.5\"],[\"118.7\",\"33.47\",\"0.5\",\"曹咀0.5\"],[\"119.22\",\"32.117\",\"0.5\",\"林场0.5\"],[\"118.684444\",\"32.586944\",\"0.5\",\"大河桥水库0.5\"],[\"118.947\",\"31.6324\",\"0.5\",\"古塘水库0.5\"],[\"118.88\",\"31.584\",\"0.5\",\"安公塘水库0.5\"],[\"119.0808\",\"31.9936\",\"0.5\",\"宁西水库0.5\"],[\"118.6861\",\"31.683\",\"0.5\",\"大岘水库0.5\"],[\"118.9736\",\"31.9596\",\"0.5\",\"邓下水库0.5\"],[\"119.031\",\"31.933\",\"0.5\",\"管头水库0.5\"],[\"118.5809\",\"31.7836\",\"0.5\",\"向阳水库0.5\"],[\"118.5097\",\"32.0821\",\"0.5\",\"唐冲水库0.5\"],[\"118.866056\",\"35.028139\",\"0.5\",\"沟屋0.5\"],[\"119.183\",\"32.117\",\"0.5\",\"亭子0.5\"],[\"118.438167\",\"34.440694\",\"0.5\",\"双龙0.5\"],[\"119.0166\",\"32.5158\",\"0.5\",\"梁洼水库0.5\"],[\"118.9404\",\"32.4923\",\"0.5\",\"毛营水库0.5\"],[\"118.8564\",\"32.4791\",\"0.5\",\"山曹水库0.5\"],[\"118.7454\",\"32.5166\",\"0.5\",\"泉林水库0.5\"],[\"118.8566\",\"32.0863\",\"0.5\",\"军民友谊水库0.5\"],[\"118.446111\",\"31.982778\",\"0.5\",\"三岔水库0.5\"],[\"118.838338\",\"32.339541\",\"0.5\",\"六合0.5\"],[\"119.1166\",\"31.5947\",\"0.5\",\"曾巷水库0.5\"],[\"118.6652\",\"31.846\",\"0.5\",\"红庙水库0.5\"],[\"118.6648\",\"31.7871\",\"0.5\",\"牌坊水库0.5\"],[\"118.5464\",\"32.0869\",\"0.5\",\"付坝水库0.5\"],[\"118.4947\",\"32.0475\",\"0.5\",\"大渔塘水库0.5\"],[\"119.22\",\"31.45\",\"0.5\",\"上沛0.5\"],[\"119.37\",\"31.25\",\"0.5\",\"中田舍0.5\"],[\"118.9306\",\"32.5019\",\"0.5\",\"唐公水库0.5\"],[\"118.7413\",\"32.566\",\"0.5\",\"龙塘水库0.5\"],[\"118.9643\",\"31.6305\",\"0.5\",\"五峰凹水库0.5\"],[\"118.8909\",\"31.5721\",\"0.5\",\"后王母塘水库0.5\"],[\"119.0079\",\"32.0021\",\"0.5\",\"马蹄肖水库0.5\"],[\"118.8502\",\"31.6695\",\"0.5\",\"排驾口水库0.5\"],[\"118.9398\",\"31.997\",\"0.5\",\"横山水库0.5\"],[\"119.0011\",\"32.3862\",\"0.5\",\"三友水库0.5\"],[\"118.9881\",\"32.447\",\"0.5\",\"陆洼水库0.5\"],[\"118.573194\",\"34.651778\",\"0.5\",\"高埝0.5\"],[\"118.972972\",\"35.007722\",\"0.5\",\"大赤涧0.5\"],[\"119.301944\",\"34.682111\",\"0.5\",\"黄泥塘0.5\"],[\"118.916667\",\"33.583333\",\"0.5\",\"淮阴闸0.5\"]]";
	private String swfPath;
	private String isExists = "Y";

	public String getIsExists() {
		return isExists;
	}

	public String getSwfPath() {
		return swfPath;
	}

	public void setId(String id) {
		this.id = id;
	}

	public void setArrayData(String arrayData) {
		this.arrayData = arrayData;
	}

	/**
	 * 绘制等值线
	 * 
	 * @param dataForm
	 *            (线条计算方式)
	 * @param lineNum
	 *            (线条值)
	 * @param arrayData
	 *            (站点数据)
	 * @param drawType
	 *            (画图类型：等值线、等值面、彩虹图)
	 * @return
	 * @throws ParseException
	 * @throws InvocationTargetException
	 * @throws IllegalAccessException
	 */
	public KmlProperty getKml(@Param("dataForm") String dataForm,
			@Param("lineNum") String lineNum,
			@Param("arrayData") String arrayData,
			@Param("drawType") String drawType) throws Exception {
		ReadKml readKml = new ReadKml();
		/*GetKml getKml= new GetKml();
		GetAreaKml getAreaKml= new GetAreaKml();*/
		Gson gson = new Gson();
		HaUserSys haUserSys = (HaUserSys) session
				.getAttribute(HA_USER_SESSION_KEY);
		HaArea area = haAreaManager.findOne(haUserSys.getAreaId());
		String areaBln = area.getName().substring(0,
				area.getName().length() - 1)
				+ "边界.bln";
		VisoLine visoLine = new VisoLine();
		String[][] src = gson.fromJson(arrayData, String[][].class);
		File file = new File(visoLine.getPath() + id + ".dat");
		if (!file.exists()) {
			visoLine.drawit(visoLine.getsrcPath(id, src), title,
					dataForm, lineNum, drawType, areaBln);

			isExists = "N";
		}
		swfPath = "d:/" + id + ".swf";
		/*return getAreaKml.readKml();*/
		return readKml.readKml();
	}
	public KmlProperty readKml() throws Exception{
		ReadKml readKml = new ReadKml();
		/*GetKml getKml = new GetKml();
		GetAreaKml getAreaKml= new GetAreaKml();*/
		return readKml.readKml();
	}

}
